package util

import (
	"os"
	"strings"
)

// CommandArgsLoad Get command line arguments
func CommandArgsLoad() map[string]string {
	argsMap := make(map[string]string)
	for _, sinArg := range os.Args[1:] {
		if sinArg == "" {
			continue
		}
		var split []string
		if split = strings.Split(sinArg, "="); len(split) != 2 {
			continue
		}
		argsMap[split[0]] = split[1]
	}
	return argsMap
}

// EnvArgsLoad Obtain environment variable parameters
func EnvArgsLoad() map[string]string {
	allEnvVars := os.Environ()
	envMap := make(map[string]string)
	for _, envVar := range allEnvVars {
		parts := strings.SplitN(envVar, "=", 2)
		if len(parts) != 2 {
			continue
		}
		envMap[parts[0]] = parts[1]
	}
	return envMap
}
